package com.yangtao.springbootfreemarker.domain.sys.dao;

import com.yangtao.core.jpa.dao.BaseJpaRepository;
import com.yangtao.springbootfreemarker.domain.sys.entity.SysMenu;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface SysMenuDao extends BaseJpaRepository<SysMenu, String> {

	/**
	 * 获取当前用户的所有菜单目录
	 * @param userId 用户ID
	 * @param orgId 组织ID
	 * @return
	 */
	@Query(value = "select DISTINCT m.* from sys_menu m " +
			" left join sys_role_menu srm on srm.menu_id = m.menu_id" +
			" left join sys_user_role sur on sur.role_id = srm.role_id" +
			" left join sys_role sr on sr.role_id = sur.role_id" +
			" where sur.user_id = ?1 and sr.org_id = ?2", nativeQuery = true)
	List<SysMenu> findAllMenuByUserId(String userId, String orgId);
}
